<?php

namespace App\Service;

class AesService
{
    //加密
    public function encrypt($str)
    {
        if (!$str) return '';
        return str_replace('+', '$', base64_encode(openssl_encrypt($str, "aes-256-cbc", 'kb-expo-2022', OPENSSL_RAW_DATA, 'kb-expo-2022-iv')));
    }

    //解密
    public function decrypt($str)
    {
        if (!$str) return '';
        $str = str_replace('$', '+', urldecode($str));
        return openssl_decrypt(base64_decode($str), "aes-256-cbc", 'kb-expo-2022', OPENSSL_RAW_DATA, 'kb-expo-2022-iv');
    }
}